﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel ;
using System.ComponentModel.Design ;
using System.Windows.Forms ;
using System.Windows.Forms.Design ;


using DotSpatial.Data;
using DotSpatial.Controls;
//using DotSpatial.Projections;
 
 

namespace HaGisPack
{
    [Serializable ]
  public  abstract  class FLayer:FObjectBase 
    {

      public FLayer(string id):base(id)
      {
          this.m_LayerType  = FLayerType.NormalLayer;
         
 
      }


      #region 对外暴露的通用属性

      protected bool m_bVisiable = true;

      /// <summary>
      /// 图层是否可见
      /// </summary>
      [Category("图层设置"), DisplayName("图层是否可见"),Browsable (false )]
      public bool IsVisible
      {
          get { return this.m_bVisiable; }
          set
          {
              this.m_bVisiable = value;
              this.OnSetVisible();
          }
      }

      protected void OnSetVisible()
      {
          if (m_bRunning)
          {
              this.ILayer.IsVisible = this.m_bVisiable;
          }

      }


      protected  FLayerType m_LayerType;

        /// <summary>
        /// 当前层类型信息
        /// </summary>
      public  FLayerType LayerType
      {
          get { return m_LayerType; }
         
      }


      /// <summary>
      /// 层内图形是否可以选择
      /// </summary>
      protected bool m_bSelectable = false;

      [DisplayName("图层是否可选择"),Browsable (false )]
      public bool BSelectable
      {
          get { return m_bSelectable; }
          set
          {
              m_bSelectable = value;
              this.OnSetSelectable();
          }
      }

      protected void OnSetSelectable()
      {
          if (m_bRunning)
          {
              this.ILayer.SelectionEnabled = this.m_bSelectable;
          }

      }



     


      #endregion



      #region 内部使用的重要属性

        [NonSerialized]
      protected  IMapLayer m_iLayer;


      [Browsable(false)]     //本属性不可见
      public virtual  IMapLayer ILayer
      {
          get { return m_iLayer; }
          set { m_iLayer = value; }
      }

       [NonSerialized ]
      protected DataSet m_DataSet;

      public DataSet DataSet
      {
          get { return m_DataSet; }
          set { m_DataSet = value; }
      }




      private bool m_bEditMode = false;

      [DisplayName("图层是否处于编辑状态"), Browsable(false)]
      protected bool BEditMode
      {
          get { return m_bEditMode; }
          set { m_bEditMode = value; }
      }

      protected void OnSetEditMode()
      {
          if (m_bRunning)
          {
              // this.ILayer.SelectionEnabled = this.m_bSelectable;
          }
      }


      protected string m_nid;



      #endregion

   




    


      
     
      protected bool m_bTextEditalbe;



        [NonSerialized]
      protected GisManager  m_ParenLManager;//保存管理器的ID

      /// <summary>
      /// 层管理器
      /// </summary>
      public GisManager ParentManger
      {
          set { m_ParenLManager = value; }
      }




   

      /// <summary>
      /// 层内图形是否可以移动
      /// </summary>
      protected bool m_bMovable = false;




      /// <summary>
      /// 图形是否可以编辑，包括删除，添加等操作
      /// </summary>
      protected bool m_bShapeEditable = true;


      /// <summary>
      /// 图形是否可以编辑，包括删除，添加等操作
      /// </summary>
      public  bool BShapeEditable
      {
          get { return m_bShapeEditable; }
          
      }





      //关于属性编辑的函数
      protected bool m_bReadRedraw = false;//这个属性用来标记，更新属性后，是否立即能够刷新显示

      protected bool m_IsShowLable = false; //是否显示标注


      /// <summary>
      /// 此标志位用于表示，层是否已经被加入管理器并生效
      /// </summary>
      private bool m_bRunning = false;

      /// <summary>
      /// 是否处于运行状态
      /// </summary>
      protected bool BRunning
      {
          get { return m_bRunning; }
       
      }

     
      /// <summary>
      /// 用于外部更新属性，而不立即执行重绘，当所有函数执行完毕后，执行endeditproperty重绘
      /// </summary>

      public void StartEditProperty()
      {
          this.m_bReadRedraw = false;
 
      }

      public void EndEditProperty()
      {
          this.m_bReadRedraw = true;

          this.Update();
 
      }


     
      /// <summary>
      /// 这个函数用来判断可能需要的刷新
      /// </summary>
      public virtual  void Update()
      {

          //当前台等一切准备好之后，才会更新属性
          if (m_bReadRedraw)
          {
              this.Redraw();
          }
 
      }


      /// <summary>
      /// 这个函数用来强制刷新层的显示，从新绘制一切,所有子类需要同过此函数实现绘制代码，这个函数假定一切状态就绪，且不可以被外部调用
      /// </summary>

      protected  virtual void Redraw()
      {
        

      }





        #region "函数"

      /// <summary>
      /// 具体子类必须重写这一函数
      /// </summary>
      protected  virtual void BuildLayer()
      {
         
 
      }

      protected virtual void BuildProp()
      {
          this.OnSetVisible();

          this.OnSetSelectable();

 
      }


      /// <summary>
      /// 对外的接口，用于从原始状态转到运行状态
      /// </summary>
      public  void BuildEntity()
      {
          this.BuildLayer();

          m_bRunning = true ;

          //复合层的父层是没有实例（dataset）的,
          if (this.m_LayerType == FLayerType.CompoundLayer) return;

          this.BuildProp();
          //进行必要的重绘操作

          this.m_bReadRedraw = true;
          this.Update();
 
      }





      public string AbsFileName
      {
          get { return this.m_ParenLManager .layerPath + this.Id+".shp"; }
      }

      public virtual  void LoadEntity()
      {
 
      }

      public virtual  void SaveEntity()
      {
           
      }

      /// <summary>
      /// 主要是用来单个图层要关闭一些参数
      /// </summary>
      public virtual void CloseLayer()
      {
      }
     

        #endregion






    }
}
